package com.example.music.adapter

import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.example.music.model.Banner

class InfiniteBannerAdapter(private val realAdapter: BannerAdapter) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
    
    private var realItemCount: Int = 0
    
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
        return realAdapter.onCreateViewHolder(parent, viewType)
    }

    override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
        if (realItemCount > 0) {
            realAdapter.onBindViewHolder(holder as BannerAdapter.BannerViewHolder, position % realItemCount)
        }
    }

    override fun getItemCount(): Int = if (realItemCount > 0) Int.MAX_VALUE else 0

    fun submitList(list: List<Banner>) {
        realItemCount = list.size
        realAdapter.submitList(list)
        notifyDataSetChanged()
    }
} 